#ifndef _CBUF_H_
#define _CBUF_H_

#include "os.h"

typedef struct CBuf
{
	int rptr;
	int wptr;


	int buf_len;

	char *buf;

}CBuf;


int cbuf_new(int initsize);
int cbuf_info(int fd);
int cbuf_isfull(int fd);
int cbuf_isempty(int fd);

int cbuf_free(int fd);

int cbuf_len(int fd);
int cbuf_size(int fd);
int cbuf_remain(int fd);

char *cbuf_rptr(int fd);
char *cbuf_wptr(int fd);
int cbuf_rlen(int fd);
int cbuf_wlen(int fd);

char *cbuf_base(int fd);

int cbuf_look_int(int fd);
int cbuf_look(int fd, void *buf, int buf_len);

int cbuf_rskip(int fd, int buf_len);
int cbuf_read(int fd, void *buf, int buf_len);
int cbuf_read_int(int fd);
short cbuf_read_short(int fd);
char cbuf_read_char(int fd);
const char *cbuf_read_utf(int fd);

int cbuf_wskip(int fd, int buf_len);

int cbuf_set_wptr(int fd, char *wptr);
int cbuf_set_rptr(int fd, char *rptr);

int cbuf_write(int fd, const void *buf, int buf_len);
int cbuf_write_int(int fd, int val);
int cbuf_write_short(int fd, short val);
int cbuf_write_char(int fd, char val);
int cbuf_write_utf(int fd, const char *val);
int cbuf_write_cbuf(int fd, int buffd, int buf_len);

int cbuf_2line(int fd);
int cbuf_double(int fd);
int cbuf_ensure(int fd, int need_size);
int cbuf_grow(int fd, int grow_size);

#endif
